package com.miyu.system.controller.opensystem;

import com.alibaba.fastjson.JSONObject;
import com.miyu.common.pojo.book.BookRuleSet;
import com.miyu.common.pojo.cos.CosCity;
import com.miyu.system.service.openSystem.OpenSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 开放系统接口
 *
 * @author longmy
 * @date 2022/04/01
 */
@RestController
@RequestMapping("sysOpen/common")
public class OpenSystem {
    @Autowired
    private OpenSystemService openSystemService;
    /**
     * 城市查询 供天气选择城市使用
     * 公开Api 无需登录调用
     * @param param
     * @return
     */
    @RequestMapping("queryCity")
    public List<CosCity> queryCity(@RequestBody JSONObject param){
        return openSystemService.queryCity();
    }

    /**
     * 得到天气
     *
     * @param param 参数
     * @return {@link JSONObject}
     */
    @RequestMapping("weather")
    public JSONObject getWeather(@RequestBody JSONObject param) throws Exception {
        String vCity = "";
        if(!param.containsKey("version")){
            param.put("version","v1");
            vCity+="v1";
        }else {
            vCity+=param.getString("version");
        }
        if(!param.containsKey("city")){
            /*默认北京*/
            param.put("city","101010100");
            vCity+="101010100";
        }else {
            vCity+=param.getString("city");
        }
        param.put("vCity",vCity);
        return openSystemService.getWeather(param);
    }
}
